package com.Pratice;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

import com.structure.Digraph;

public class PREV49{
	static int[] a;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int len = scan.nextInt();
		Digraph gh = new Digraph(len);
		List<Integer> res = new ArrayList();
		for (int i = 0; i < len; i++) {
			gh.addEdge(scan.nextInt(), scan.nextInt());
		}
		gh.isCycle();
		for (int i : gh.cycleV) 
			System.out.print(i + " ");
	}
}